// pages/publish.js
import  areaList  from '../../utils/area';
Page({
  data: {
    showcity: false,
    showdate:false,
    city:'',
    areaList,
    currentDate: new Date().getTime(),
    minDate: new Date(2015, 1, 1).getTime(),
    maxDate: new Date(2022, 12, 31).getTime(),
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      } 
      if (type === 'month') {
        return `${value}月`;
      }
      return value;
    },
  },

  onLoad: function (options) {
  },

  onShow: function (options) {

  },

  selectCity:function(event){
    this.setData({ showcity: true })
  },

  onClose(){
    this.setData({ showcity: false })
    this.setData({ showdate: false })
  },

  onConfirmCity(val){
    let city = val.detail.values[0].name + " " + val.detail.values[1].name + " " + val.detail.values[2].name
    this.setData({ city: city })
    this.setData({ showcity: false })
  },

  onCancel(){
    this.setData({ showcity: false })
    this.setData({ showdate: false })
  },

  selectDate:function(event){
    this.setData({ showdate: true })
  },

  onInput(event) {
    this.setData({
      currentDate: event.detail,
    })
    this.setData({ showdate: false })
  },

  onConfirmDate(event){
    this.setData({
      currentDate: event.detail,
      date: this.timeFormat(event.detail)
    })
    this.setData({ showdate: false })
  },

  // 自定义时间格式化函数
  timeFormat(time) { 
    var date = new Date(time * 1)
    let year = date.getFullYear()
    let month = date.getMonth() + 1
    let day = date.getDate()
    return year + '年' + month + '月' + day + '日'
  }

})